package com.evil.kingdom.pojo.enums;

import com.evil.common.core.exception.BusinessException;
import com.evil.kingdom.pojo.enums.result.RCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 方阵布局类型
 *
 * @author liyang
 * @date 2024-07-03 09:57
 */
@Getter
@AllArgsConstructor
public enum PhalanxLayoutEnum {

    DEFAULT(0, "默认"),
    MARSHAL(1, "元帅"),
    FRONT(2, "前军"),
    MIDDLE(3, "中军"),
    BACK(4, "后军"),
    ;

    private final int type;
    private final String title;

    public static Optional<PhalanxLayoutEnum> isExistByType(Integer type) {
        if (null == type) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.type == type).findFirst();
    }

    public static PhalanxLayoutEnum findByType(Integer type) {
        return PhalanxLayoutEnum.isExistByType(type).orElseThrow(PhalanxLayoutEnum::error);
    }

    public static BusinessException error() {
        return new BusinessException(RCodeEnum.ERROR_PARAMETER, "方阵布局类型错误");
    }
}
